﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="TutorAdvanced.ItemDetailPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TutorAdvanced"
    xmlns:data="using:TutorAdvanced.Data"
    xmlns:common="using:TutorAdvanced.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <!-- Collection of items displayed by this page -->
        <CollectionViewSource
            x:Name="itemsViewSource"
            Source="{Binding Items}"
            d:Source="{Binding AllGroups[0].Items, Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}"/>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid
        Style="{StaticResource LayoutRootStyle}"
        DataContext="{Binding Group}"
        d:DataContext="{Binding AllGroups[0], Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}">
    	<Grid.Background>
    		<ImageBrush ImageSource="Assets/bg2.png" Stretch="UniformToFill"/>
    	</Grid.Background>

        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--
            The remainder of the page is one large FlipView that displays details for
            one item at a time, allowing the user to flip through all items in the chosen
            group
        -->
        <FlipView
            x:Name="flipView"
            AutomationProperties.AutomationId="ItemsFlipView"
            AutomationProperties.Name="Item Details"
            TabIndex="1"
            Grid.RowSpan="2"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}">

            <FlipView.ItemContainerStyle>
                <Style TargetType="FlipViewItem">
                    <Setter Property="Margin" Value="0,137,0,0"/>
                </Style>
            </FlipView.ItemContainerStyle>

            <FlipView.ItemTemplate>
                <DataTemplate>

                    <!--
                        UserControl chosen as the templated item because it supports visual state management
                        Loaded/unloaded events explicitly subscribe to view state updates from the page
                    -->
                    <UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
                        <ScrollViewer x:Name="scrollViewer" Style="{StaticResource HorizontalScrollViewerStyle}" Grid.Row="1">

                            <!-- Content is allowed to flow across as many columns as needed -->
                            <Grid HorizontalAlignment="Center" VerticalAlignment="Top" Height="515">
                            	<Grid.RowDefinitions>
                            		<RowDefinition Height="400"/>
                            		<RowDefinition Height="60
									"/>
                            		<RowDefinition Height="60"/>
                            	</Grid.RowDefinitions>
                        		<RichTextBlock x:Name="richTextBlock" Style="{StaticResource ItemRichTextStyle}" IsTextSelectionEnabled="False" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center">
                            		
                            		<Paragraph LineStackingStrategy="MaxHeight">
                            			<InlineUIContainer>
                            				<Image x:Name="image" MaxHeight="480" Margin="0" Stretch="Uniform" Source="{Binding Image}" AutomationProperties.Name="{Binding Title}"/>
                            			</InlineUIContainer>
                            		</Paragraph>
                            		<Paragraph>
                            		</Paragraph>
                            	</RichTextBlock>

                        		<common:RichTextColumns x:Name="richTextColumns" Grid.RowSpan="3" Margin="0,0,0,29.667">

                        			<!-- Additional columns are created from this template -->
                        			<common:RichTextColumns.ColumnTemplate>
                        				<DataTemplate>
                        					<RichTextBlockOverflow Width="560" Margin="80,0,0,0">
                        						<RichTextBlockOverflow.RenderTransform>
                        							<TranslateTransform X="-1" Y="4"/>
                        						</RichTextBlockOverflow.RenderTransform>
                        					</RichTextBlockOverflow>
                        				</DataTemplate>
                        			</common:RichTextColumns.ColumnTemplate>

                        		</common:RichTextColumns>
                        		<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="Square" VerticalAlignment="Top" Grid.Row="1" Foreground="#FF406724" FontFamily="Segoe UI" FontSize="28"/>
                        		<Grid x:Name="Controls" HorizontalAlignment="Center" Height="39" VerticalAlignment="Center" Grid.Row="2" Background="Black" Margin="0">
                        			<StackPanel Orientation="Horizontal">
                        				<Grid x:Name="Play" HorizontalAlignment="Left" Margin="9,9,0,0">
                        					<Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Source="Assets/Icon3.png"/>
                        				</Grid>
                        				<Grid x:Name="Space" Height="20" Margin="15,0,10,0">
                        					<Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Source="Assets/IconSpace.png"/>
                        				</Grid>
                        				<Grid Width="326">
                        					<Slider Style="{StaticResource SliderStyle1}" VerticalAlignment="Top" Maximum="100" Margin="-3,-3,0,0" Value="20"/>
                        				</Grid>
                        				<Grid x:Name="Space2" Height="20" Margin="15,9.5,10,9.5">
                        					<Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Source="Assets/IconSpace.png"/>
                        				</Grid>
                        				<Grid x:Name="Sound" HorizontalAlignment="Left" Margin="9,9,0,0">
                        					<Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Source="Assets/Icon2.png" Margin="0,0,8,0"/>
                        				</Grid>
                        				<Grid Width="100">
                        					<Slider Style="{StaticResource SliderStyle1}" VerticalAlignment="Top" Maximum="100" Margin="0,-3,0,0" Value="20"/>
                        				</Grid>
                        				<Grid x:Name="Space3" Height="20" Margin="15,9.5,10,9.5">
                        					<Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Source="Assets/IconSpace.png"/>
                        				</Grid>
                        				<Grid x:Name="Screen" HorizontalAlignment="Left" Margin="9,9,0,0">
                        					<Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Source="Assets/Icon1.png" Margin="0,0,8,0"/>
                        				</Grid>
                        			</StackPanel>
                        		</Grid>

                        	</Grid>

                            <VisualStateManager.VisualStateGroups>

                                <!-- Visual states reflect the application's view state inside the FlipView -->
                                <VisualStateGroup x:Name="ApplicationViewStates">
                                    <VisualState x:Name="FullScreenLandscape"/>
                                    <VisualState x:Name="Filled"/>

                                    <!-- Respect the narrower 100-pixel margin convention for portrait -->
                                    <VisualState x:Name="FullScreenPortrait">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="richTextColumns" Storyboard.TargetProperty="Margin">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="97,0,87,57"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="image" Storyboard.TargetProperty="MaxHeight">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="400"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>

                                    <!-- When snapped, the content is reformatted and scrolls vertically -->
                                    <VisualState x:Name="Snapped">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="richTextColumns" Storyboard.TargetProperty="Margin">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="17,0,17,57"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="scrollViewer" Storyboard.TargetProperty="Style">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource VerticalScrollViewerStyle}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="richTextBlock" Storyboard.TargetProperty="Width">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="280"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="image" Storyboard.TargetProperty="MaxHeight">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="160"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </ScrollViewer>
                    </UserControl>
                </DataTemplate>
            </FlipView.ItemTemplate>
        </FlipView>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <Grid x:Name="TopLogo" HorizontalAlignment="Left" Height="100" VerticalAlignment="Center" Width="234" Grid.Column="1" Margin="-19,0,0,0">
            	<Image Source="Assets/MainLogo.png"/>
            </Grid>
        </Grid>
        <Grid x:Name="Sneped" HorizontalAlignment="Left" Height="100" Opacity="0" VerticalAlignment="Top" Width="100">
        	<TextBlock x:Name="textBlock" HorizontalAlignment="Center" TextWrapping="Wrap" Text="Please switch to full screen to view the details." VerticalAlignment="Center" Margin="12.776,349.417,12.223,348.583" FontFamily="Segoe UI" FontSize="26" Foreground="#FF272727" Opacity="0"/>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape">
                	<Storyboard>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="TopLogo">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Thickness>0</Thickness>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                	</Storyboard>
                </VisualState>
                <VisualState x:Name="Filled"/>

                <!-- The back button respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="TopLogo">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Thickness>-19,0,0,0</Thickness>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="flipView">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Sneped" d:IsOptimized="True" To="1"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="Sneped">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<x:Double>NaN</x:Double>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="Sneped">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<x:Double>NaN</x:Double>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="Sneped">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<HorizontalAlignment>Stretch</HorizontalAlignment>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.VerticalAlignment)" Storyboard.TargetName="Sneped">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<VerticalAlignment>Stretch</VerticalAlignment>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.RowSpan)" Storyboard.TargetName="Sneped">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<x:Int32>3</x:Int32>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock" d:IsOptimized="True" To="1"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="TopLogo">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
